﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace CDV.MC.MatrixDriver.WebApp
{
    /// <summary>
    /// 启动类
    /// </summary>
    public class Program
    {
        /// <summary>
        /// 入口方法
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            BuildWebHost(args).Run();
        }

        /// <summary>
        /// 构建WebHost
        /// </summary>
        /// <param name="args">--urls="http://*:8080"</param>
        /// <returns></returns>
        public static IWebHost BuildWebHost(string[] args)
        {
            //配置通过读取命令行参数获取监听URL
            var config = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddCommandLine(args)
                .Build();

            return WebHost.CreateDefaultBuilder(args)
                     .UseConfiguration(config)
                     .UseStartup<Startup>()
                     .UseKestrel()
                     //.UseUrls("http://*:51158")//监听本机端口51158（启用通过IP地址访问）
                     .Build();
        }
    }
}
